package com.wp.targetOffer;

/**
 * Created by 王萍 on 2017/7/29 0029.
 */
public class 二进制中1的个数 {

    public static void main(String[] args) {
        System.out.println(NumberOf1(7));
    }

    public static int NumberOf1(int n) {
        int number=0;
        while (n!=0){
            number++;
            n=n&(n-1);
        }
        return number;
    }
}
